import java.util.Scanner;
import java.util.Arrays;
import java.util.*;


public class Main {
    /**
     * 乒乓球框
     * https://www.nowcoder.com/questionTerminal/bb4f1a23dbb84fd7b77be1fbe9eaaf32
     * @param args
     */
    public static void main1(String[] args)
    {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int[] hash = new int[26];
            char[] s1 = in.next().toCharArray();
            char[] s2 = in.next().toCharArray();

            for(int i = 0;i < s1.length;i++)
                hash[s1[i] - 'A']++;

            boolean flat = true;
            for(int j = 0;j < s2.length;j++)
            {
                if(--hash[s2[j] - 'A'] < 0)
                {
                    flat =false;
                    break;
                }
            }

            System.out.println(flat == true ? "Yes" : "No");

        }
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int[] arr = new int[3 * n];

        for(int i = 0;i < 3 * n;i++){
            arr[i] = in.nextInt();
        }

        Arrays.sort(arr);

        int pos = 3 * n - 2,count = 1;
        long sum = 0;
        while(count <= n){
            sum += arr[pos];
            count++;
            pos -= 2;
        }

        System.out.println(sum);
    }

    /**
     * 删除相邻数的最大分数
     * https://www.nowcoder.com/practice/3bcf72c738b6494bbe1ebe0ffde56152?tpId=230&tqId=40419&ru=/exam/oj
     */


    static int N = (int)1e4 + 10;
        static int[] sum = new int[N];
        static int[] f = new int[N];
        static int[] g = new int[N];

        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);

            int n = in.nextInt();
            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                sum[x] += x;
            }


            for (int j = 1; j < N; j++) {
                f[j] = sum[j] + g[j - 1];
                g[j] = Math.max(f[j - 1], g[j - 1]);
            }
            System.out.println(Math.max(f[N -1], g[N - 1]));
        }

}